﻿using System.Linq;
using Infrastructure.Orm.Queries;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Infrastructure.Tests.ORMTests
{
    [TestClass]
    public class OrmWildcardQueriesTest : OrmTestsBase
    {
        [TestMethod]
        public void OrmWildcardQueriesTest_WildcardOnLeft()
        {

            const string artistName = "Dean Martin";
            const string song1 = "That's Amore";
            const string song2 = "Christmas Blues";
            var artist = new Artist
                             {
                                 ArtistName = artistName
                             };
            artist.AddTrack(new Track { TrackName = song1 });
            artist.AddTrack(new Track { TrackName = song2 });
            using (var unitOfWork = GetKeyedUnitOfWork<Artist>())
            {
                unitOfWork.MakePersistent(artist);
            }
            using (var unitOfWork = GetKeyedUnitOfWork<Artist>())
            {
                var query = new Query<Artist>().StringLike(a => a.ArtistName, "*Martin");
                Assert.AreEqual(artist, unitOfWork.GetByQuery(query).Single());
            }
        }
    }
}
